<?php

if (!defined('NV_ADMIN')) {
    die ("Access Denied");
}
/*************************************
Creat by http://sangkienvnpt.com
Dat link den http://sangkienvnpt.com khi ban su dung module nay
Version 1.0
***************************************/


$checkmodname = "Vanban";
$adm_access = checkmodac("".$checkmodname."");
if ($adm_access == 1) {
if (file_exists("language/".$checkmodname."_".$currentlang.".php")) {
	include_once("language/".$checkmodname."_".$currentlang.".php");
	
}
if (file_exists("../$datafold/config_".$checkmodname.".php")) {
	include_once("../$datafold/config_".$checkmodname.".php");
}
define("IMG_PATH", "../images/modules/".$checkmodname."/");




$vpath = "../".$pathv."";
    function getparent($parentid,$title) {
    global $prefix,$db;
    $sql = "select cid, title, parentid from ".$prefix."_vanban_theloai where cid='$parentid'";
    $result = $db->sql_query($sql);
    $row = $db->sql_fetchrow($result);
    $cid = $row[cid];
    $ptitle = $row[title];
    $pparentid = $row[parentid];
    if ($ptitle!="") $title=$ptitle."/".$title;
    if ($pparentid!=0) {
        $title=getparent($pparentid,$title);
    }
    return $title;
}

    function menu() {
    echo "<center><b>"._PAGESADMIN."</b><br><br>[ <a href=admin.php?op=vanban#1>"._HOMEADMINPAGE."</a> | <a href=admin.php?op=vanban_add_page#1>"._ADDPAGE."</a> | <a href=admin.php?op=vanban_cat#1>"._ADMINCAT."</a> | <a href=admin.php?op=vanban_config#1>"._CAUHINH."</a>]</center>";
    }
function vanban() {
   global $prefix, $db, $multilingual, $pagenum, $adminfile, $sotrang;
    include("../header.php");
    GraphicAdmin();
    OpenTable();
    echo "<a name=1></a>";
    menu();
    CloseTable();
    echo "<br>";
    OpenTable();
    $bgcolor1= "#EBF8E1";
    $bgcolor2= "#D7F2D7";
    $bgcolor3= "#008000";
    $num = $db->sql_numrows($db->sql_query("SELECT * FROM ".$prefix."_vanban"));
    if($num >0) {
    echo "<center><b>"._ALLPAGES." $num "._PAGES."</b></center><br><br>";
    echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"$bgcolor3\" width=\"100%\">\n"
    ."<tr><td width=\"100%\"><table border=\"0\" cellpadding=\"3\" cellspacing=\"1\" width=\"100%\">\n"
    ."<tr><td width=\"40%\" bgcolor=\"$bgcolor3\" align=\"center\"><b>"._TIEUDE."</b></td>\n"
    ."<td width=\"20%\" bgcolor=\"$bgcolor3\" align=\"center\"><b>"._EXISTCAT."</b></td>\n"
    ."<td width=\"20%\" bgcolor=\"$bgcolor3\" align=\"center\"><b>"._PAGESTATUS."</b></td>\n"
    ."<td width=\"20%\" bgcolor=\"$bgcolor3\" align=\"center\"><b>"._ADMINENTER."</b></td></tr>";

    if ($pagenum == "") { $pagenum = 1; $storynum = $sotrang; } else $storynum = $sotrang;
    $offset = ($pagenum-1) * $storynum ;

    $sql = "SELECT pid, cid, title, active FROM ".$prefix."_vanban ORDER BY pid DESC limit $offset, $storynum";
    $result = $db->sql_query($sql);
    $a = 1;
    while ($row = $db->sql_fetchrow($result)) {
    $pid = $row[pid];
    $cid = $row[cid];
    $title = $row[title];
    $active = $row[active];
    if ($active == 0) { $act = ""._NOACTIVE.""; $actedit = "<a href=$adminfile.php?op=vanban_status_page&pid=$pid&act=off>"._OFFPAGE."</a>"; }
    if ($active == 1) { $act = ""._YESACTIVE.""; $actedit = "<a href=$adminfile.php?op=vanban_status_page&pid=$pid&act=on>"._ONPAGE."</a>"; }
    if ($cid == 0) {
    $cat_title = ""._HOMECAT."";
    }
    else {
    $sql2 = "SELECT title FROM ".$prefix."_vanban_theloai WHERE cid='$cid'";
    $result2 = $db->sql_query($sql2);
    $row = $db->sql_fetchrow($result2);
    $cat_title = $row[title];
    }

    if ($a == 1) { $bgc = "bgcolor=\"$bgcolor1\""; }
    if ($a == 2) { $bgc = "bgcolor=\"$bgcolor2\""; }

    echo "<tr><td width=\"40%\" $bgc>$title</td>\n"
    ."<td width=\"20%\" $bgc align=\"center\">$cat_title</td>\n"
    ."<td width=\"20%\" $bgc align=\"center\">$act</td>\n"
    ."<td width=\"20%\" $bgc align=\"center\"><a href=$adminfile.php?op=vanban_delit_page&pid=$pid>"._DELPAGE."</a> <a href=$adminfile.php?op=vanban_edit_page&pid=$pid>"._EDITPAGE."</a> $actedit</td></tr>";
    $a++;
    if ($a == 3) { $a = 1; }
    }


    echo "</table></td></tr></table>";
   #START Page Numbers
   
    $sql_pn = "select * from ".$prefix."_vanban";
    $result_pn = $db->sql_query($sql_pn);
    $numstories = $db->sql_numrows($result_pn);
    @$numpages = ceil($numstories / $storynum);
    if ($numpages > 1) {
        echo "<hr><center>" ;
        if ($pagenum > 1) {
            $prevpage = $pagenum - 1 ;
                        $leftarrow = "../modules/Vanban/images/prev_page.gif" ;
                echo "<a href=\"$adminfile.php?op=vanban&amp;pagenum=$prevpage\">";
                echo "<img src=\"$leftarrow\" align=\"absmiddle\" border=\"0\" hspace=\"10\"></a>";
        }
        for ($i=1; $i < $numpages+1; $i++) {

            if ($i == $pagenum) {
                echo "<b>$i</b>";
            }
            else {
            $pagelink = 10;
            if (($i > $pagenum) AND ($i < $pagenum+$pagelink) OR ($i < $pagenum) AND ($i > $pagenum-$pagelink)) {
            echo " <a href=\"$adminfile.php?op=vanban&amp;pagenum=$i\">$i</a> ";
            }
            if (($i == $numpages) AND ($pagenum < $numpages-$pagelink)){
            echo "... <a href=\"$adminfile.php?op=vanban&amp;pagenum=$i\">$i</a>";
            }
            if (($i == 1) AND ($pagenum > 1+$pagelink)){
            echo "<a href=\"$adminfile.php?op=vanban&amp;pagenum=$i\">$i</a> ...";
            }
            }
        }
        if ($pagenum < $numpages) {
            $nextpage = $pagenum + 1 ;
                        $rightarrow = "../modules/Vanban/images/next_page.gif" ;
                echo "<a href=\"$adminfile.php?op=vanban&amp;pagenum=$nextpage\">";
                echo "<img src=\"$rightarrow\" align=\"absmiddle\" border=\"0\" hspace=\"10\"></a>";
        }
        echo "</center>" ;
    }
    #END Page Numbers

    }   
    else {
    echo "<center><b>"._NOUPAGES."</b></center>";
    }
    
    CloseTable();
    
    include("../footer.php");
}


function vanban_cat() {
    global $prefix, $db, $multilingual, $adminfile;
    include("../header.php");
    GraphicAdmin();
    OpenTable();
    echo "<a name=1></a>";
    menu();
    CloseTable();
    echo "<br>";
    echo "<br>";

// Them the loai van ban moi

    OpenTable();
    echo "<center><b>"._ADDPAGESCAT."</b></center><br><br>"
        ."<form action=\"$adminfile.php\" method=\"post\">"
        ."<b>"._ADDPAGESCAT.":</b><br><input type=\"text\" name=\"title\" size=\"60\"><br><br>";
        
    if ($multilingual == 1) {
        echo "<br><b>"._LANGUAGE.": </b>"
            ."<select name=\"alanguage\">";
        $handle=opendir('../language');
        while ($file = readdir($handle)) {
            if (preg_match("/^lang\-(.+)\.php/", $file, $matches)) {
                $langFound = $matches[1];
                $languageslist .= "$langFound ";
            }
        }
        closedir($handle);
        $languageslist = explode(" ", $languageslist);
        sort($languageslist);
        for ($i=0; $i < sizeof($languageslist); $i++) {
            if($languageslist[$i]!="") {
                echo "<option value=\"$languageslist[$i]\" ";
                if($languageslist[$i]==$alanguage) echo "selected";
                echo ">".ucfirst($languageslist[$i])."</option>\n";
            }
        }
        if ($alanguage == "") {
            $sellang = "selected";
        } else {
            $sellang = "";
        }
        echo "<option value=\"\" $sellang>"._ALL."</option></select><br><br>";
    } else {
        echo "<input type=\"hidden\" name=\"alanguage\" value=\"\">";
    }
    echo "<input type=\"hidden\" name=\"op\" value=\"vanban_add_category\">"
        ."<input type=\"submit\" value=\""._ADDPAGESCAT."\">"
        ."</form>";
    CloseTable();
    echo "<br>";

// Add a New Sub-Category

    $sql = "select cid, title, parentid from ".$prefix."_vanban_theloai order by parentid,title";
        $result = $db->sql_query($sql);
    if ($numrows = $db->sql_numrows($result) > 0) {
        OpenTable();
    echo "<form method=\"post\" action=\"$adminfile.php\">"
        ."<center><b>"._ADDSUBCATEGORY."</b></center><br><br>"
        ."<b>"._INCATV.":</b><br>"
        ."<select name=\"cid\">";

    while ($row = $db->sql_fetchrow($result)) {
     $cid2 = $row[cid];
     $title = $row[title];
     $parentid2 = $row[parentid];
                if ($parentid2!=0) $title=getparent($parentid2,$title);
                echo "<option value=\"$cid2\">$title</option>";
                }
    echo "</select><br><br>"
        ."<b>"._SOHIEU.":</b><br><input type=\"text\" name=\"title\" size=\"60\"><br><br>"
        ."<input type=\"hidden\" name=\"op\" value=\"vanban_add_sub_category\">"
        ."<input type=\"submit\" value=\""._ADDSUBCATEGORY."\"></form>";
        CloseTable();
        echo "<br>";
    }

// Edit a Category

     $sql = "select cid, title, parentid from ".$prefix."_vanban_theloai order by parentid,title";
     $result = $db->sql_query($sql);
     if ($numrows = $db->sql_numrows($result) > 0) {
     OpenTable();
      echo "<center><b>"._EDITPAGECAT."</b></center><br><br>";
      echo "<table border=\"1\" style=\"BORDER-COLLAPSE: collapse\"  borderColor=\"#008000\" cellpadding=\"2\" cellspacing=\"0\" width=\"100%\">";
      
     while ($row = $db->sql_fetchrow($result)) {
     $cid2 = $row[cid];
     $title = $row[title];
     $parentid2 = $row[parentid];
                if ($parentid2!=0) $title=getparent($parentid2,$title);
                echo "<tr>";
                echo "<td>".$title."</td>";
                echo "<td><center>[<a href=\"$adminfile.php?op=edit_vanban_category&amp;cid=$cid2\">"._EDIT."</a> ][<a href=\"$adminfile.php?op=vanban_del_category&amp;cid=$cid2\">"._DELETE."</a> ]</center></td>";
                echo "</tr>";       
      
          }
         echo "</table>";
        CloseTable();
    }
include("../footer.php");
}

function edit_vanban_category($cid) {
    global $prefix, $db, $multilingual, $adminfile;
    include("../header.php");
    GraphicAdmin();
    OpenTable();
    menu();
    CloseTable();
    echo "<br>";
    OpenTable();
    $cid = intval($cid);
    $sql = "SELECT title, parentid FROM ".$prefix."_vanban_theloai WHERE cid='$cid'";
    $result = $db->sql_query($sql);
    $row = $db->sql_fetchrow($result);
    $title = $row[title];
    $parentid = $row[parentid];
    echo "<center><b>"._EDITPAGECAT."</b></center><br><br>"
        ."<form action=\"$adminfile.php\" method=\"post\">"
        ."<b>"._SOHIEU."</b><br>"
        ."<input type=\"text\" name=\"title\" value=\"$title\" size=\"60\"><br><br>";
        if ($parentid != 0) {
        $sql2 = "select cid, title, parentid from ".$prefix."_vanban_theloai where parentid != '$parentid'";
        $result2 = $db->sql_query($sql2);
        echo "<b>"._EXISTCAT.":</b><br><select name=\"parentid\">";
        while ($row = $db->sql_fetchrow($result2)) {
        $cid2 = $row[cid];
        $ctitle2 = $row[title];
        $parentid2 = $row[parentid];
        if ($row[cid] == $cid) {
            $sel = "selected";
        } else {
            $sel = "";
        }
                if ($parentid2!=0) $ctitle2=getparent($parentid2,$ctitle2);
            echo "<option value=\"$cid2\" $sel>$ctitle2</option>";
        }
        echo "</select><br><br>";
        }
        else { echo "<input type=\"hidden\" name=\"parentid\" value=\"0\">"; }
        if (($multilingual == 1) AND ($parentid == 0)) {
        echo "<br><b>"._LANGUAGE.": </b>"
            ."<select name=\"alanguage\">";
        $handle=opendir('../language');
        while ($file = readdir($handle)) {
            if (preg_match("/^lang\-(.+)\.php/", $file, $matches)) {
                $langFound = $matches[1];
                $languageslist .= "$langFound ";
            }
        }
        closedir($handle);
        $languageslist = explode(" ", $languageslist);
        sort($languageslist);
        for ($i=0; $i < sizeof($languageslist); $i++) {
            if($languageslist[$i]!="") {
                echo "<option value=\"$languageslist[$i]\" ";
                if($languageslist[$i]==$language) echo "selected";
                echo ">".ucfirst($languageslist[$i])."</option>\n";
            }
        }
        echo "<option value=\"\">"._ALL."</option></select><br><br>";
    } else {
        echo "<input type=\"hidden\" name=\"alanguage\" value=\"$language\">";
    }
        echo "<b>"._SUBTITLE."</b><br>"
        ."<input type=\"hidden\" name=\"cid\" value=\"$cid\">"
        ."<input type=\"hidden\" name=\"op\" value=\"vanban_save_category\">"
        ."<input type=\"submit\" value=\""._SAVECHANGES."\">&nbsp;&nbsp;"
        ."[ <a href=\"$adminfile.php?op=vanban_del_category&amp;cid=$cid\">"._DELETE."</a> ]"
        ."</form>";
    CloseTable();
    include("../footer.php");
}

function vanban_add_category($title,  $alanguage) {
    global $prefix, $db, $adminfile;
    $db->sql_query("INSERT INTO ".$prefix."_vanban_theloai (cid, title, parentid, planguage) VALUES (NULL, '$title',  '0', '$alanguage')");
  echo "INSERT INTO ".$prefix."_vanban_theloai (cid, title, parentid, planguage) VALUES (NULL, '$title',  '0', '$alanguage')";
    Header("Location: $adminfile.php?op=vanban_cat");
}

function vanban_add_sub_category($cid, $title) {
    global $prefix, $db, $adminfile;
    $db->sql_query("INSERT INTO ".$prefix."_vanban_theloai (cid, title, parentid) VALUES (NULL, '$title',  '$cid')");
    Header("Location: $adminfile.php?op=vanban_cat");
}

function vanban_save_category($cid, $title,  $parentid, $alanguage) {
    global $prefix, $db,$adminfile;
    $db->sql_query("UPDATE ".$prefix."_vanban_theloai SET title='$title',  parentid='$parentid', planguage='$alanguage' WHERE cid='$cid'");
    Header("Location: $adminfile.php?op=vanban_cat");
}

function vanban_del_category($cid, $ok) {
    global $prefix, $db, $adminfile,$vpath;
    $cid = intval($cid);
    if($ok) {
    	/////////////////////////////
   $sql = "select url from ".$prefix."_vanban where cid='$cid'";
    $result = $db->sql_query($sql);
    while ($row = $db->sql_fetchrow($result)){
    $urlfile = $row[url];
     $oldfile = array_reverse(explode("/", $urlfile));
   if ((file_exists($vpath."/".$oldfile[0]))){ 
        
        $delf = "".$vpath."/".$oldfile[0]."";
        @unlink($delf);
        }}
        
    $db->sql_query("DELETE FROM ".$prefix."_vanban WHERE cid='$cid'");
    $db->sql_query("DELETE FROM ".$prefix."_vanban_theloai WHERE parentid='$cid'");
    $db->sql_query("DELETE FROM ".$prefix."_vanban_theloai WHERE cid='$cid'");
    Header("Location: $adminfile.php?op=vanban_cat");
    }
    
    else {
    $sql = "select title, parentid from ".$prefix."_vanban_theloai where cid='$cid'";
    $result = $db->sql_query($sql);
    $row = $db->sql_fetchrow($result);
    $cat_title = $row[title];
    $parentid = $row[parentid];

    $numcat = $db->sql_numrows($db->sql_query("select * from ".$prefix."_vanban_theloai where parentid='$cid'"));
    $numpages = $db->sql_numrows($db->sql_query("select * from ".$prefix."_vanban where cid='$cid'"));
    include("../header.php");
    GraphicAdmin();
    OpenTable();
    menu();
    CloseTable();
    echo "<br>";
    OpenTable();
    echo "<center><b>"._DELPAGECAT."<br><br>"._DELNOTE."</b><br><br>";
    echo ""._DELNOTE1." <b>$cat_title</b>, "._DELNOTE2.": <b>$numcat</b> "._DELNOTE3.": <b>$numpages</b>.<br><br>";
    echo ""._DELNOTE4."<br><br>[ <a href=\"$adminfile.php?op=vanban_cat\"><b>"._NO."</b></a> | <a href=\"$adminfile.php?op=vanban_del_category&amp;cid=$cid&amp;ok=1\"><b>"._YES."</b></a> ]</center><br><br>";
    CloseTable();
    include("../footer.php");
    }
}

/*
function vanban_add_page() {
    global $prefix, $db, $toolbars,$hourdiff,$adminfile ;
    include("../header.php");
    GraphicAdmin();
    OpenTable();
    echo "<a name=1></a>";
    menu();
    CloseTable();
    echo "<br>";
    
    echo "<br>";
    OpenTable();
    echo "<form enctype=\"multipart/form-data\" action=\"".$adminfile.".php\" method=\"post\">"
        ."<b>"._SOHIEU."</b><br>"
        ."<input  type=\"text\"  name=\"title\"  size=\"80\" maxlength=\"255\"><br><br>"
        ."<b>"._INCATV.":</b><br>"
        ."<select name=\"cid\"><option value=\"0\">"._HOMECAT."</option>";
           $sql = "select cid, title, parentid from ".$prefix."_vanban_theloai order by parentid,title";
           $result = $db->sql_query($sql);
           while ($row = $db->sql_fetchrow($result)) {
           $cid2 = $row[cid];
           $title = $row[title];
           $parentid2 = $row[parentid];
                if ($parentid2!=0) $title=getparent($parentid2,$title);
                echo "<option value=\"$cid2\">$title</option>";
                
                }
    echo "</select><br><br>";
    echo "<b>"._HOMETEXTPAGE."</b><br>";
    echo "<textarea class=sinput name=\"hometext\"  rows=\"3\"></textarea><br><br>";
    echo "<b>"._BODYTEXTPAGE."</b><br>";
    echo "<textarea class=sinput name=\"bodytext\" rows=\"20\"></textarea><br><br>";
    
    // Bat dau phan them ngay
    echo "<b>"._CHONNGAY."</b><br><br>";
    echo ""._DAY.": <select name=\"day\">";
	for($i=1;$i <= 31;$i++) {
		echo "<option value=\"".str_pad($i, 2, "0", STR_PAD_LEFT)."\"";
		if($i == date("d",time()+$hourdiff * 60)) { echo " selected"; }
		echo ">".str_pad($i, 2, "0", STR_PAD_LEFT)."</option>\n";
	}
	echo "</select>";
	echo ""._UMONTH.": <select name=\"month\">";
	for($i=1;$i <= 12;$i++) {
		echo "<option value=\"".str_pad($i, 2, "0", STR_PAD_LEFT)."\"";
		if($i == date("m",time()+$hourdiff * 60)) { echo " selected"; }
		echo ">".str_pad($i, 2, "0", STR_PAD_LEFT)."</option>\n";
	}
	echo "</select>";
	echo ""._YEAR.": <select name=\"year\">";
	$z = date("Y",time()+$hourdiff * 60);
	for($i=$z;$i <= $z+4;$i++) {
		echo "<option value=\"$i\"";
		if($i == $z) { echo " selected"; }
		echo ">$i</option>\n";
	}
	echo "</select>";
	echo "<br><br>";
	// ket thuc phan them ngay
    
    echo "<b>"._CHUTHE.":</b><br>"
        ."<input type=\"text\" name=\"chuthe\" size=\"100\" maxlength=\"255\"><br><br>";
    echo "<b>"._NGUOIKY.":</b><br>"
        ."<input type=\"text\" name=\"nguoiky\" size=\"100\" maxlength=\"255\"><br><br>";
    echo "<b>"._FILE.":</b><br><input name=\"uservan\" type=\"file\" size=\"40\"><br><br>";
    echo "<b>"._FILELINK.":</b><br><input type=\"text\" name=\"filelink\" size=\"50\" maxlength=\"100\" value=\"http://\"><br><br>";
            
    echo "<b>"._ACTIVPAGE."</b> <input type=\"checkbox\" name=\"active\" value=\"1\" checked><br><br>"
        ."<select name=\"op\">"
        ."<option selected value=\"vanban_save_page\">"._ADDPAGE."</option>"
        ."<option value=\"vanban_preview_page\">"._PREVIEWPAGE."</option></select> "
        ."<input type=\"submit\" value=\""._NEXTSTEP."\"></form>";

    CloseTable();
    include("../footer.php");
}
*/
function vanban_add_page() {
        global $prefix,$editor, $db, $toolbars,$hourdiff,$adminfile ;
        include("../header.php");
        GraphicAdmin();
        OpenTable();
        echo "<a name=1></a>";
        menu();
        CloseTable();
        echo "<br>";
       
        echo "<br>";
        OpenTable();
        echo "<form enctype=\"multipart/form-data\" action=\"".$adminfile.".php\" method=\"post\">"
            ."<b>"._SOHIEU."</b><br>"
            ."<input  type=\"text\"  name=\"title\"  size=\"80\" maxlength=\"255\"><br><br>"
            ."<b>"._INCATV.":</b><br>"
            ."<select name=\"cid\"><option value=\"0\">"._HOMECAT."</option>";
               $sql = "select cid, title, parentid from ".$prefix."_vanban_theloai order by parentid,title";
               $result = $db->sql_query($sql);
               while ($row = $db->sql_fetchrow($result)) {
               $cid2 = $row[cid];
               $title = $row[title];
               $parentid2 = $row[parentid];
                    if ($parentid2!=0) $title=getparent($parentid2,$title);
                    echo "<option value=\"$cid2\">$title</option>";
                   
                    }
        echo "</select><br><br>";
        echo "<b>"._HOMETEXTPAGE."</b><br>";
        echo "<textarea class=sinput name=\"hometext\"  rows=\"3\"></textarea><br><br>";
        echo "<b>"._BODYTEXTPAGE."</b><br>";
        if($editor==1) {
    aleditor("comment","",300,200);
    } else {
        echo "<textarea class=sinput name=\"bodytext\" rows=\"20\" wrap=\"virtual\" cols=\"80\"></textarea><br><br>";
        }
        // Bat dau phan them ngay
        echo "<b>"._CHONNGAY."</b><br><br>";
        echo ""._DAY.": <select name=\"day\">";
       for($i=1;$i <= 31;$i++) {
          echo "<option value=\"".str_pad($i, 2, "0", STR_PAD_LEFT)."\"";
          if($i == date("d",time()+$hourdiff * 60)) { echo " selected"; }
          echo ">".str_pad($i, 2, "0", STR_PAD_LEFT)."</option>\n";
       }
       echo "</select>";
       echo ""._UMONTH.": <select name=\"month\">";
       for($i=1;$i <= 12;$i++) {
          echo "<option value=\"".str_pad($i, 2, "0", STR_PAD_LEFT)."\"";
          if($i == date("m",time()+$hourdiff * 60)) { echo " selected"; }
          echo ">".str_pad($i, 2, "0", STR_PAD_LEFT)."</option>\n";
       }
       echo "</select>";
       echo ""._YEAR.": <select name=\"year\">";
//       $z = date("Y",time()+$hourdiff * 60)-62;
       $z = 2008;//date("Y",time());
	   for($i=$z-62;$i <= $z;$i++) {
          echo "<option value=\"$i\"";
          if($i == $z) { echo " selected"; }
          echo ">$i</option>\n";
       }
       echo "</select>";
       echo "<br><br>";
       // ket thuc phan them ngay
       
        echo "<b>"._CHUTHE.":</b><br>"
            ."<input type=\"text\" name=\"chuthe\" size=\"100\" maxlength=\"255\"><br><br>";
        echo "<b>"._NGUOIKY.":</b><br>"
            ."<input type=\"text\" name=\"nguoiky\" size=\"100\" maxlength=\"255\"><br><br>";
        echo "<b>"._FILE.":</b><br><input name=\"uservan\" type=\"file\" size=\"40\"><br><br>";
        echo "<b>"._FILELINK.":</b><br><input type=\"text\" name=\"filelink\" size=\"50\" maxlength=\"100\" value=\"http://\"><br><br>";
               
        echo "<b>"._ACTIVPAGE."</b> <input type=\"checkbox\" name=\"active\" value=\"1\" checked><br><br>"
            ."<select name=\"op\">"
            ."<option selected value=\"vanban_save_page\">"._ADDPAGE."</option>"
            ."<option value=\"vanban_preview_page\">"._PREVIEWPAGE."</option></select> "
            ."<input type=\"submit\" value=\""._NEXTSTEP."\"></form>";

        CloseTable();
        include("../footer.php");
    }

function vanban_preview_page($cid, $title,$hometext, $bodytext,  $day, $month, $year, $chuthe, $nguoiky, $uservan, $filelink, $active) {
global $prefix, $db, $toolbars,$hourdiff,$pathv, $vpath, $adminfile ;
    $f_hometext = nl2br(stripslashes($hometext));
    $title = stripslashes($title);
    $hometext = stripslashes($hometext);
    $bodytext = stripslashes($bodytext);
    $chuthe = stripslashes($chuthe);
    $nguoiky = stripslashes($nguoiky);
    $filelink = stripslashes(FixQuotes($filelink));
    $uservan = stripslashes(FixQuotes($uservan));
    
    

    include("../header.php");
    GraphicAdmin();
    OpenTable();
    menu();
    CloseTable();
    echo "<br>";
    OpenTable();
    echo "<center><b>"._SEEPAGE."</b></center><hr>";
    echo "<b>$title</b><br><br>$f_hometext<br><br>$bodytext<br><br>$chuthe<br><br>$nguoiky<br><br>";
    CloseTable();
    echo "<br>";
    OpenTable();
    echo "<form enctype=\"multipart/form-data\" action=\"".$adminfile.".php\" method=\"post\">"
        ."<b>"._SOHIEU."</b><br>"
        ."<input class=sinput type=\"text\" name=\"title\" value=\"$title\"><br><br>"
        ."<b>"._INCATV.":</b><br>"
        ."<select name=\"cid\"><option value=\"0\">"._HOMECAT."</option>";

           $sql = "select cid, title, parentid from ".$prefix."_vanban_theloai order by parentid,title";
           $result = $db->sql_query($sql);
           while ($row = $db->sql_fetchrow($result)) {
           $cid2 = $row[cid];
           $title = $row[title];
           $parentid2 = $row[parentid];
                if ($parentid2!=0) $title=getparent($parentid2,$title);
                if ($cid == $cid2) {
                $sel = "selected";
                } else {
                $sel = "";
                }
                echo "<option value=\"$cid2\" $sel>$title</option>";
                }
    echo "</select><br><br>";
    echo "<b>"._HOMETEXTPAGE."</b><br>";
    echo "<textarea class=sinput name=\"hometext\" rows=\"3\">$hometext</textarea><br><br>";
    echo "<b>"._BODYTEXTPAGE."</b><br>";
    echo "<textarea class=sinput name=\"bodytext\" rows=\"20\">$bodytext</textarea><br><br>";
    
    // Bat dau phan them ngay
    echo "<b>"._CHONNGAY."</b><br><br>";
    
    echo ""._DAY.": <select name=\"day\">";
	for($i=1;$i <= 31;$i++) {
		echo "<option value=\"".str_pad($i, 2, "0", STR_PAD_LEFT)."\"";
		if($i == $day) { echo " selected"; }
		echo ">".str_pad($i, 2, "0", STR_PAD_LEFT)."</option>\n";
	}
	echo "</select>";
	echo ""._UMONTH.": <select name=\"month\">";
	for($i=1;$i <= 12;$i++) {
		echo "<option value=\"".str_pad($i, 2, "0", STR_PAD_LEFT)."\"";
		if($i == $month) { echo " selected"; }
		echo ">".str_pad($i, 2, "0", STR_PAD_LEFT)."</option>\n";
	}
	echo "</select>";
	echo ""._YEAR.": <select name=\"year\">";
	$z = date("Y",time()+$hourdiff * 60);
	for($i=$z;$i <= $z+4;$i++) {
		echo "<option value=\"$i\"";
		if($i == $year) { echo " selected"; }
		echo ">$i</option>\n";
	}
	echo "</select>";
    echo "<br><br>";
	// ket thuc phan them ngay
    echo "<b>"._CHUTHE.":</b><br>"
        ."<input type=\"text\" name=\"chuthe\" size=\"100\" maxlength=\"255\" value=\"$chuthe\"><br><br>";
    echo "<b>"._NGUOIKY.":</b><br>"
        ."<input type=\"text\" name=\"nguoiky\" size=\"100\" maxlength=\"255\" value=\"$nguoiky\"><br><br>";
    echo "<b>"._FILE.":</b><br><input name=\"uservan\" type=\"file\" size=\"40\" value=\"$uservan\"><br><br>";
    echo "<b>"._FILELINK.":</b><br><input type=\"text\" name=\"filelink\" size=\"50\" maxlength=\"100\" value=\"$filelink\"><br><br>";
    
    echo "<b>"._ACTIVPAGE."</b> ";
    if ($active == 1) {
    echo "<input type=\"checkbox\" name=\"active\" value=\"1\" checked><br><br>";
    }
    else {
     echo "<input type=\"checkbox\" name=\"active\" value=\"1\"><br><br>";
    }
    echo "<select name=\"op\">"
        ."<option selected value=\"vanban_save_page\">"._ADDPAGE."</option>"
        ."<option value=\"vanban_preview_page\">"._PREVIEWPAGE."</option></select> "
        ."<input type=\"submit\" value=\""._NEXTSTEP."\"></form>";

    CloseTable();
    include("../footer.php");
}

function vanban_save_page($cid, $title, $hometext, $bodytext, $day, $month, $year,$chuthe,$nguoiky,$filelink, $active) {
    global $prefix, $db, $adminfile, $pathv, $vpath, $nukeurlv;
    if (strlen($title)>0){
    if ($filelink == "http://") { $filelink = ""; }
    $title = stripslashes(FixQuotes($title));
    $hometext = nl2br(stripslashes(FixQuotes($hometext)));
    $bodytext = stripslashes(FixQuotes($bodytext));
    $day = str_pad(intval($day), 2, "0", STR_PAD_LEFT);
    $month = str_pad(intval($month), 2, "0", STR_PAD_LEFT);
    $year = intval($year);
    $acttime = mktime(0, 0, 0, $month, $day, $year) - $hourdiff * 60;
    $date = date("Y-m-d H:i:s",$acttime);
    $filelink = stripslashes(FixQuotes($filelink));
    $db->sql_query("INSERT INTO ".$prefix."_vanban (pid, cid, title, hometext, bodytext, date, chuthe, nguoiky, url, active) VALUES (NULL, '$cid', '$title', '$hometext','$bodytext', '$date', '$chuthe', '$nguoiky','ckt.gov.vn', '$active')");
    
    $sql = "select MAX(pid) from ".$prefix."_vanban ";
        $res = $db->sql_query($sql);
        $row = $db->sql_fetchrow($res);
        $vid = intval($row[0]);
    
    //Bat dau them file upload
    if (isset($vid)){
     if ((is_uploaded_file($_FILES['uservan']['tmp_name']))) {
     if ((file_exists($vpath."/".$_FILES['uservan']['name']))){ 
     include("../header.php");
     GraphicAdmin();
    OpenTable();
    menu();
    CloseTable();
    echo "<br>";
    OpenTable();
     echo "<center><br><br>"._FILEEXIST."<br><br><a href='admin.php?op=vanban_add_page#1'>"._BACK."</center>\n";
     CloseTable();
     include("../footer.php");
     exit;
     }
  
     $extension = explode('.',$_FILES['uservan']['name']);
     $filename = $extension[0]."_".$vid.'.'.$extension[1];
     
     $filesize = $_FILES['uservan']['size'];
     if(! @copy($_FILES['uservan']['tmp_name'], "$vpath/$filename") ) {
		if (! move_uploaded_file($_FILES['uservan']['tmp_name'], $vpath ."/". $filename)) {
			include("../header.php");
    GraphicAdmin();
    OpenTable();
    menu();
    CloseTable();
    echo "<br>";
    OpenTable();
			echo "<center><br><br>"._UPLOADFAULT." $pathv .<br><br><a href='admin.php?op=vanban_add_page#1'>"._BACK."</center>\n";
			CloseTable();
			include("../footer.php");
			exit;
		}
	}
     $filename = "".$nukeurlv."/".$pathv."/".$filename."";

     }
     else {
     
     $filename = $filelink;
     
     }  
  }else {include("../header.php");
    GraphicAdmin();
    OpenTable();
    menu();
    CloseTable();
    echo "<br>";
    OpenTable();
			echo "<center><br><br>"._UPLOADFAULT."$pathv .<br><br><a href='admin.php?op=vanban_add_page#1'>"._BACK."</center>\n";
			CloseTable();
			include("../footer.php");
			exit; }
//ket thuc them file upload
        
    $db->sql_query("UPDATE ".$prefix."_vanban SET url='$filename' WHERE pid='$vid'");
    Header("Location: $adminfile.php?op=vanban_add_page#1 ");
    }else {include("../header.php");
    GraphicAdmin();
    OpenTable();
    menu();
    CloseTable();
    echo "<br>";
    OpenTable();
			echo "<center><br><br>"._THIEUTITLE." <br><br><a href='admin.php?op=vanban_add_page#1'>"._BACK."</center>\n";
			CloseTable();
			include("../footer.php");
			exit; }
    	
}

function vanban_edit_page($pid) {
global $prefix, $db, $toolbars,$hourdiff,$pathv, $vpath, $adminfile ;

    $sql = "SELECT cid, title,hometext, bodytext, chuthe, nguoiky, url, UNIX_TIMESTAMP(date) as formatted, active  FROM ".$prefix."_vanban WHERE pid='$pid'";
    $result = $db->sql_query($sql);
    $row = $db->sql_fetchrow($result);
    $cid = $row[cid];
    $title = $row[title];
    $hometext = $row[hometext];
    $bodytext = $row[bodytext];
    $chuthe = $row[chuthe];
    $nguoiky = $row[nguoiky];
    $url = $row[url];
    $date = intval($row['formatted']);
    $active = $row[active];

    include("../header.php");
    GraphicAdmin();
    OpenTable();
    menu();
    CloseTable();
    echo "<br>";
    OpenTable();
    echo "<center><b>"._PAGEEDIT."<br><br>"._SEEPAGE2."</b></center><hr>";
    echo "<b>$title</b><br><br>$hometext<br><br>$bodytext<br><br>$chuthe<br><br>$nguoiky<br><br>";
    CloseTable();
    echo "<br>";
    OpenTable();
    echo "<form enctype=\"multipart/form-data\" action=\"".$adminfile.".php\" method=\"post\">"
        ."<b>"._SOHIEU."</b><br>"
        ."<input class=sinput type=\"text\" name=\"title\" value=\"$title\"><br><br>"
        ."<b>"._INCATV.":</b><br>"
        ."<select name=\"cid\"><option value=\"0\">"._HOMECAT."</option>";

           $sql = "select cid, title, parentid from ".$prefix."_vanban_theloai order by parentid,title";
           $result = $db->sql_query($sql);
           while ($row = $db->sql_fetchrow($result)) {
           $cid2 = $row[cid];
           $title = $row[title];
           $parentid2 = $row[parentid];
                if ($parentid2!=0) $title=getparent($parentid2,$title);
                if ($cid == $cid2) {
                $sel = "selected";
                } else {
                $sel = "";
                }
                echo "<option value=\"$cid2\" $sel>$title</option>";
                }
    echo "</select><br><br>";
    echo "<b>"._HOMETEXTPAGE."</b><br>";
    echo "<textarea class=sinput name=\"hometext\" rows=\"3\">$hometext</textarea><br><br>";
    echo "<b>"._BODYTEXTPAGE."</b><br>";
    echo "<textarea class=sinput name=\"bodytext\" rows=\"20\">$bodytext</textarea><br><br>";
    
    // Bat dau phan them ngay
    echo "<b>"._CHONNGAY."</b><br><br>";
    
    
   echo ""._DAY.": <select name=\"day\">";
	for($i=1;$i <= 31;$i++) {
		echo "<option value=\"".str_pad($i, 2, "0", STR_PAD_LEFT)."\"";
		if($i == date("d",$date+$hourdiff * 60)) { echo " selected"; }
		echo ">".str_pad($i, 2, "0", STR_PAD_LEFT)."</option>\n";
	}
	echo "</select>";
	echo ""._UMONTH.": <select name=\"month\">";
	for($i=1;$i <= 12;$i++) {
		echo "<option value=\"".str_pad($i, 2, "0", STR_PAD_LEFT)."\"";
		if($i == date("m",$date+$hourdiff * 60)) { echo " selected"; }
		echo ">".str_pad($i, 2, "0", STR_PAD_LEFT)."</option>\n";
	}
	echo "</select>";
	echo ""._YEAR.": <select name=\"year\">";
	$z = 2008; //date("Y",$date+$hourdiff * 60);
	for($i=$z-62; $i <= $z+4; $i++) {
		echo "<option value=\"$i\"";
		if($i == $z) { echo " selected"; }
		echo ">$i</option>\n";
	}
	echo "</select>";
    echo "<br><br>";
	// ket thuc phan them ngay
    echo "<b>"._CHUTHE.":</b><br>"
        ."<input type=\"text\" name=\"chuthe\" size=\"100\" maxlength=\"255\" value=\"$chuthe\"><br><br>";
    echo "<b>"._NGUOIKY.":</b><br>"
        ."<input type=\"text\" name=\"nguoiky\" size=\"100\" maxlength=\"255\" value=\"$nguoiky\"><br><br>";
    echo "<b>"._FILENEW. ":</b>&nbsp "._LUUY."<br><input name=\"uservan\" type=\"file\" size=\"40\" ><br><br>";
    echo "<b>"._LINKNOW.":</b><br><input type=\"text\" name=\"filelink\" size=\"50\" maxlength=\"100\" value=\"$url\"><br><br>";
    
    echo "<b>"._ACTIVPAGE."</b> ";
    if ($active == 1) {
    echo "<input type=\"checkbox\" name=\"active\" value=\"1\" checked><br><br>";
    }
    else {
     echo "<input type=\"checkbox\" name=\"active\" value=\"1\"><br><br>";
    }
    
    echo "<input type=\"hidden\" name=\"op\" value=\"vanban_edit_sv_page\">"
        ."<input type=\"hidden\" name=\"pid\" value=\"$pid\">"
        ."<input type=\"submit\" value=\""._SAVEPAGE."\">"
        ."</form>";
    
     

    CloseTable();
    include("../footer.php");
}


function vanban_edit_sv_page($pid, $cid, $title, $hometext, $bodytext, $day, $month, $year,$chuthe,$nguoiky,$filelink, $active) {
    global $prefix, $db, $adminfile, $pathv, $vpath, $nukeurlv;
    if ($filelink == "http://") { $filelink = ""; }
    $title = stripslashes(FixQuotes($title));
    $hometext = nl2br(stripslashes(FixQuotes($hometext)));
    $bodytext = stripslashes(FixQuotes($bodytext));
    $day = str_pad(intval($day), 2, "0", STR_PAD_LEFT);
    $month = str_pad(intval($month), 2, "0", STR_PAD_LEFT);
    $year = intval($year);
    $acttime = mktime(0, 0, 0, $month, $day, $year) - $hourdiff * 60;
    $date = date("Y-m-d H:i:s",$acttime);
    $filelink = stripslashes(FixQuotes($filelink));
    
    
    $sql = "select pid from ".$prefix."_vanban WHERE pid='$pid'";
        $res = $db->sql_query($sql);
        $row = $db->sql_fetchrow($res);
        $vid = intval($row[0]);
        
    
    //Bat dau them file upload
    if (isset($vid)){
     if ((is_uploaded_file($_FILES['uservan']['tmp_name']))) {
     if ((file_exists($vpath."/".$_FILES['uservan']['name']))){ 
     include("../header.php");
     GraphicAdmin();
    OpenTable();
    menu();
    CloseTable();
    echo "<br>";
    OpenTable();
     echo "<center><br><br>"._FILEEXIST."<br><br></center>\n";
     CloseTable();
     include("../footer.php");
     exit;
     }
  
     $extension = explode('.',$_FILES['uservan']['name']);
     $filename = $extension[0]."_".$vid.'.'.$extension[1];
     
     $filesize = $_FILES['uservan']['size'];
     if(! @copy($_FILES['uservan']['tmp_name'], "$vpath/$filename") ) {
		if (! move_uploaded_file($_FILES['uservan']['tmp_name'], $vpath ."/". $filename)) {
			include("../header.php");
    GraphicAdmin();
    OpenTable();
    menu();
    CloseTable();
    echo "<br>";
    OpenTable();
			echo "<center><br><br>"._UPLOADFAULT." $pathv .<br><br></center>\n";
			CloseTable();
			include("../footer.php");
			exit;
		}
	}
     $filename = "".$nukeurlv."/".$pathv."/".$filename."";
      $oldfile = array_reverse(explode("/",$filelink));
    
     }
     else {
     
     $filename = $filelink;
     
     }  
  }else {include("../header.php");
    GraphicAdmin();
    OpenTable();
    menu();
    CloseTable();
    echo "<br>";
    OpenTable();
			echo "<center><br><br>"._UPLOADFAULT." $pathv .<br><br></center>\n";
			CloseTable();
			include("../footer.php");
			exit; }
 
    
//ket thuc them file upload
    $db->sql_query("UPDATE ".$prefix."_vanban SET cid='$cid', title='$title', hometext='$hometext', bodytext='$bodytext', chuthe='$chuthe', nguoiky='$nguoiky', url='$filename', date='$date', active='$active'  WHERE pid='$pid'");
    if(!($filename==$filelink)){
    $oldfile = array_reverse(explode("/", $filelink));
   if ((file_exists($vpath."/".$oldfile[0]))){ 
        
        $delf = "".$vpath."/".$oldfile[0]."";
        @unlink($delf);
        }
   
   }
    Header("Location: $adminfile.php?op=vanban");
}

function vanban_delit_page($pid, $ok) {
    global $prefix, $db, $adminfile, $vpath;
    $cid = intval($cid);
    if($ok) {
    $sql = "select url from ".$prefix."_vanban where pid='$pid'";
    $result = $db->sql_query($sql);
    $row = $db->sql_fetchrow($result);
    $urlfile = $row[url];
     $oldfile = array_reverse(explode("/", $urlfile));
   if ((file_exists($vpath."/".$oldfile[0]))){ 
        
        $delf = "".$vpath."/".$oldfile[0]."";
        @unlink($delf);
        }
   $db->sql_query("DELETE FROM ".$prefix."_vanban WHERE pid='$pid'");
   
    Header("Location: admin.php?op=vanban#1");
    }
    else {
    $sql = "select title from ".$prefix."_vanban where pid='$pid'";
    $result = $db->sql_query($sql);
    $row = $db->sql_fetchrow($result);
    $title = $row[title];
    

    include("../header.php");
    GraphicAdmin();
    OpenTable();
    menu();
    CloseTable();
    echo "<br>";
    OpenTable();
    echo "<center><b>"._DELPAGES."</b><br><br>";
    echo ""._DELPAGENOTE1." <b>$title</b>.<br><br>";
    echo ""._DELPAGENOTE2."<br><br>[ <a href=\"admin.php?op=vanban#1\"><b>"._NO."</b></a> | <a href=\"admin.php?op=vanban_delit_page&amp;pid=$pid&amp;ok=1\"><b>"._YES."</b></a> ]</center><br><br>";
    CloseTable();
    include("../footer.php");
    }
}

function vanban_status_page($pid, $act) {
    global $prefix, $db;
    if ($act == "off") {
    $db->sql_query("UPDATE ".$prefix."_vanban SET active='1' WHERE pid='$pid'");
    }
    if ($act == "on") {
    $db->sql_query("UPDATE ".$prefix."_vanban SET active='0' WHERE pid='$pid'");
    }
    Header("Location: admin.php?op=vanban");
}


function vanban_config() {
    global $prefix, $db,$adminfile, $pathv, $index,$pagecatlink,$newhome,$newhomenum,$numpage,$pagecatnumlinc,$vpath, $nukeurlv, $sotrang,$outpage,$vnocat;
    include("../header.php");
    GraphicAdmin();
    OpenTable();
    echo "<a name=1></a>";
    menu();
    CloseTable();
    echo "<br>";
    
    echo "<br>";
    OpenTable();
    title(_SETTING);
    
     echo "<form action=\"".$adminfile.".php\" method=\"post\">";
    OpenTable();
    echo "<table border=\"0\">"
    ."<tr><td>"
    .""._INDEX.":</td><td>";
    if ($index==1) {
    echo "<input type=\"radio\" name=\"vindex\" value=\"1\" checked>"._YES." &nbsp;"
    ."<input type=\"radio\" name=\"vindex\" value=\"0\">"._NO."";
    }else {
    echo "<input type=\"radio\" name=\"vindex\" value=\"1\">"._YES." &nbsp;"
    ."<input type=\"radio\" name=\"vindex\" value=\"0\" checked>"._NO."";
    }
    echo "</td></tr>"
     ."<tr><td>"
     .""._CATLINK.":</td><td>";
    if ($pagecatlink==1) {
    	echo "<input type=\"radio\" name=\"vpagecatlink\" value=\"1\" checked>"._YES." &nbsp;"
	."<input type=\"radio\" name=\"vpagecatlink\" value=\"0\">"._NO."";
    } else {
    	echo "<input type=\"radio\" name=\"vpagecatlink\" value=\"1\">"._YES." &nbsp;"
	."<input type=\"radio\" name=\"vpagecatlink\" value=\"0\" checked>"._NO."";
    }
        echo "</td></tr>\n"
   ."<tr><td>"
     .""._NEWHOME.":</td><td>";
    if ($newhome==1) {
    	echo "<input type=\"radio\" name=\"vnewhome\" value=\"1\" checked>"._YES." &nbsp;"
	."<input type=\"radio\" name=\"vnewhome\" value=\"0\">"._NO."";
    } else {
    	echo "<input type=\"radio\" name=\"vnewhome\" value=\"1\">"._YES." &nbsp;"
	."<input type=\"radio\" name=\"vnewhome\" value=\"0\" checked>"._NO."";
    }
        echo "</td></tr>\n"
        ."<tr><td>"
     .""._PAGEOUT.":</td><td>";
    if ($vnocat==1) {
    	echo "<input type=\"radio\" name=\"vpageout\" value=\"1\" checked>"._YES." &nbsp;"
	."<input type=\"radio\" name=\"vpageout\" value=\"0\">"._NO."";
    } else {
    	echo "<input type=\"radio\" name=\"vpageout\" value=\"1\">"._YES." &nbsp;"
	."<input type=\"radio\" name=\"vpageout\" value=\"0\" checked>"._NO."";
    }
        echo "</td></tr>\n"
        
      ."<tr><td>"._NEWHOMENUM.":</td><td><select name=\"vnewhomenum\">";
        for ($d=0;$d<=20 ;$d++) {
        $seld = "";
        if ($d == $newhomenum) { $seld = " selected"; }
        echo"<option name=\"vnewhomenum\" value=\"$d\" $seld>$d</option>\n";
        }
        echo "</select></td></tr>";
       
    echo "<tr><td>"._NUMPAGE.":</td><td><select name=\"vnumpage\">";
        for ($d=0;$d<=20 ;$d++) {
        $seld = "";
        if ($d == $numpage) { $seld = " selected"; }
        echo"<option name=\"vnumpage\" value=\"$d\" $seld>$d</option>\n";
        }
      echo "</select></td></tr>";
   echo "<tr><td>"._CUNGTHELOAI.":</td><td><select name=\"vpagecatnumlinc\">";
      for ($d=0;$d<=20 ;$d++) {
        $seld = "";
        if ($d == $pagecatnumlinc) { $seld = " selected"; }
        echo"<option name=\"vpagecatnumlinc\" value=\"$d\" $seld>$d</option>\n";
        }
      echo "</select></td></tr>";
      echo "<tr><td>"._SOTRANG.":</td><td><select name=\"pageadmin\">";
        for ($d=0;$d<=20 ;$d++) {
        $seld = "";
        if ($d == $sotrang) { $seld = " selected"; }
        echo"<option name=\"pageadmin\" value=\"$d\" $seld>$d</option>\n";
        }
      echo "</select></td></tr>";
      echo "<tr><td>"._PAGEOUTNUM.":</td><td><select name=\"pageoutnum\">";
        for ($d=0;$d<=20 ;$d++) {
        $seld = "";
        if ($d == $outpage) { $seld = " selected"; }
        echo"<option name=\"pageoutnum\" value=\"$d\" $seld>$d</option>\n";
        }
      echo "</select></td></tr>";
      echo "<tr><td>\n"     
        .""._VANBANDIR.":</td><td>"
        ."<input type=\"text\" name=\"vpathv\" value=\"$pathv\" size=\"30\">";
       echo "</td></tr>"
     
         ."<tr><td>"     
        .""._URLSITE.":</td><td>"
        ."<input type=\"text\" name=\"vnukeurlv\" value=\"$nukeurlv\" size=\"30\">";
       echo "</td></tr>"
            ."</table>";
      CloseTable();
      echo"<br>"
        ."<input type=\"hidden\" name=\"op\" value=\"VBSettingSave\">"
        ."<center><input type=\"submit\" value=\""._SAVECONF."\"></center>"
        ."</form>";
    
    CloseTable();
    include("../footer.php");
}

function VBSettingSave() {
 global $checkmodname, $datafold, $adminfile;
 
 $vindex  	     = intval($_POST['vindex']);
 $vpagecatlink       = intval($_POST['vpagecatlink']);
 $vnewhome           = intval($_POST['vnewhome']);
 $vnewhomenum        = intval($_POST['vnewhomenum']);
 $vnumpage           = intval($_POST['vnumpage']);
 $vpagecatnumlinc    = intval($_POST['vpagecatnumlinc']);
 $pageadmin          = intval($_POST['pageadmin']);
 $vpageout           = intval($_POST['vpageout']);
 $pageoutnum         = intval($_POST['pageoutnum']);
 $vpathv	     = FixQuotes($_POST['vpathv']);
 $vnukeurlv          = FixQuotes($_POST['vnukeurlv']);
 
 

@chmod("".INCLUDE_PATH."".$datafold."/config_".$checkmodname.".php", 0777);
@$file = fopen("".INCLUDE_PATH."".$datafold."/config_".$checkmodname.".php", "w");
    
	$content = "<?php\n\n";
	$vctime = date("d-m-Y H:i:s",filectime ("".INCLUDE_PATH."".$datafold."/config_".$checkmodname.".php"));
	$fmtime = date("d-m-Y H:i:s");
	$content .= "// File: config_".$checkmodname.".php.\n// Created: $vctime.\n// Modified: $fmtime.\n// Do not change anything in this file!\n\n";
	$content .= "if (eregi(\"n_config.php\",\$_SERVER['PHP_SELF'])) {\n";
	$content .= "Header(\"Location: index.php\");\n";
	$content .= "die();\n";
	$content .= "}\n";
	$content .= "\n";
	$content .= "\$index = $vindex;\n";
	$content .= "\$pagecatlink = $vpagecatlink;\n";
	$content .= "\$newhome = $vnewhome;\n";
	$content .= "\$numpage = $vnumpage;\n";
	$content .= "\$pagecatnumlinc = $vpagecatnumlinc;\n";
	$content .= "\$sotrang = $pageadmin;\n";
	$content .= "\$vnocat = $vpageout;\n";
	$content .= "\$outpage = $pageoutnum;\n";
	$content .= "\$newhomenum = $vnewhomenum;\n";
	$content .= "\$pathv = \"$vpathv\";\n";
//	$content .= "\$nukeurlv = \"$vnukeurlv\";\n";
//	$content .= "\$banquyen = \"..................................................<br> <a href='http://sangkienvnpt.com'>Copyright Sangkienvnpt.com</a> <br>..................................................<br>\";\n";
	$content .= "\n";
	$content .= "?>";
    @fwrite($file, $content);
    @fclose($file);
    @chmod("".INCLUDE_PATH."".$datafold."/config_".$checkmodname.".php", 0604);
       
    include("../header.php");
    GraphicAdmin();
    OpenTable();
    	echo "<center><b>"._CHUYEN."</b></center>";
	echo "<META HTTP-EQUIV=\"refresh\" content=\"2;URL=".$adminfile.".php?op=vanban_config#1\">";
	CloseTable();
	include("../footer.php");
}
	
switch ($op) {

    case "vanban":
    vanban();
    break;

    case "vanban_cat":
    vanban_cat();
    break;

    case "vanban_add_category":
    vanban_add_category($title,  $alanguage);
    break;

    case "vanban_add_sub_category":
    vanban_add_sub_category($cid, $title );
    break;

    case "edit_vanban_category":
    edit_vanban_category($cid);
    break;

    case "vanban_save_category":
    vanban_save_category($cid, $title,  $parentid, $alanguage);
    break;

    case "vanban_del_category":
    vanban_del_category($cid, $ok);
    break;

    case "vanban_add_page":
    vanban_add_page();
    break;

    case "vanban_preview_page":
    vanban_preview_page($cid, $title,$hometext, $bodytext,  $day, $month, $year, $chuthe, $nguoiky, $uservan, $filelink, $active) ;
    break;

    case "vanban_save_page":
     vanban_save_page($cid, $title, $hometext, $bodytext, $day, $month, $year,$chuthe,$nguoiky,$filelink, $active);
    break;

    case "vanban_edit_page":
    vanban_edit_page($pid);
    break;

    case "vanban_edit_sv_page":
    vanban_edit_sv_page($pid, $cid, $title, $hometext, $bodytext, $day, $month, $year,$chuthe,$nguoiky,$filelink, $active) ;
    break;

    case "vanban_delit_page":
    vanban_delit_page($pid, $ok);
    break;

    case "vanban_status_page":
    vanban_status_page($pid, $act);
    break;
    case "vanban_config":
    vanban_config();
    break;
    case "VBSettingSave":
     VBSettingSave();
    break;
}
}

?>